package cn.com.blueInfo.bpm.number.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.number.request.NumberLogDTO;
import cn.com.blueInfo.bpm.number.response.NumberLogVO;
import cn.com.blueInfo.bpm.number.service.NumberLogService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 编号规则日志表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:05
 */
@Tag(name = "编号规则日志 接口")
@RestController
@RequestMapping("/number/numberLog")
public class NumberLogController extends BaseController {

    @Autowired
    private NumberLogService numberLogService;

    /**
     * 新建编号规则日志
     * @param numberLogDTO 编号规则日志参数
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则日志")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createNumberLog(
            @Validated({Create.class, Default.class}) @RequestBody NumberLogDTO numberLogDTO) {
        return numberLogService.addNumberLog(numberLogDTO);
    }

    /**
     * 批量新建编号规则日志
     * @param numberLogDTOList 编号规则日志参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建编号规则日志")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateNumberLog(
            @Validated({Create.class, Default.class}) @RequestBody List<NumberLogDTO> numberLogDTOList) {
        return numberLogService.batchAddNumberLog(numberLogDTOList);
    }

    /**
     * 根据ID删除编号规则日志
     * @param numberLogId 编号规则日志ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则日志")
    @DeleteMapping("/removeInfo/{numberLogId}")
    public ResultInfo<Integer> deleteNumberLogById(
            @Parameter(name = "ID") @PathVariable Long numberLogId) {
        return numberLogService.removeNumberLog(numberLogId);
    }

    /**
     * 批量根据ID删除编号规则日志
     * @param numberLogIdList 编号规则日志ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除编号规则日志")
    @DeleteMapping("/removeInfoList/{numberLogIdList}")
    public ResultInfo<Integer> batchDeleteNumberLogByIds(
            @Parameter(name = "ID") @PathVariable List<Long> numberLogIdList) {
        return numberLogService.batchRemoveNumberLog(numberLogIdList);
    }

    /**
     * 根据ID全量更新编号规则日志
     * @param numberLogId 编号规则日志ID
     * @param numberLogDTO 编号规则日志参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新编号规则日志")
    @PutMapping("/modifyInfo/{numberLogId}")
    public ResultInfo<Integer> updateNumberLogFull(
            @Parameter(name = "ID") @PathVariable Long numberLogId,
            @Validated({Update.class, Default.class}) @RequestBody NumberLogDTO numberLogDTO) {
        validateUpdateId(numberLogId, numberLogDTO.getId());
        return numberLogService.modifyNumberLog(numberLogDTO);
    }

    /**
     * 根据ID部分更新编号规则日志
     * @param numberLogId 编号规则日志ID
     * @param numberLogUpdatePartialDTO 编号规则日志参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新编号规则日志")
    @PatchMapping("/modifyPartialInfo/{numberLogId}")
    public ResultInfo<Integer> updateNumberLogPartial(
            @Parameter(name = "ID") @PathVariable Long numberLogId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            NumberLogDTO.UpdatePartialDTO numberLogUpdatePartialDTO) {
        validateUpdateId(numberLogId, numberLogUpdatePartialDTO.getId());
        return numberLogService.modifyNumberLogPartial(numberLogUpdatePartialDTO);
    }

    /**
     * 根据ID查询编号规则日志
     * @param numberLogId 编号规则日志ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询编号规则日志")
    @GetMapping("/getInfo/{numberLogId}")
    public ResultInfo<NumberLogVO> getNumberLogById(
            @Parameter(name = "ID") @PathVariable Long numberLogId) {
        return numberLogService.queryNumberLogById(numberLogId);
    }

    /**
     * 分页查询编号规则日志
     * @param numberLogQueryDTO 编号规则日志参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询编号规则日志")
    @GetMapping("/getInfos")
    public ResultInfo<Page<NumberLogVO>> getNumberLogPage(
            @Validated NumberLogDTO.QueryDTO numberLogQueryDTO) {
        return numberLogService.queryNumberLogPage(numberLogQueryDTO);
    }

    /**
     * 根据条件查询编号规则日志
     * @param numberLogQueryDTO 编号规则日志参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询编号规则日志")
    @GetMapping("/getInfoList")
    public ResultInfo<List<NumberLogVO>> getNumberLogList(
            @Validated NumberLogDTO.QueryDTO numberLogQueryDTO) {
        return numberLogService.queryNumberLogList(numberLogQueryDTO);
    }

}
